package com.ruoyi.system.service.impl;

import java.util.List;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.system.domain.AppUser;
import com.ruoyi.system.mapper.AppUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.AppUserRelationMapper;
import com.ruoyi.system.domain.AppUserRelation;
import com.ruoyi.system.service.IAppUserRelationService;

/**
 * 好友Service业务层处理
 *
 * @author ruoyi
 * @date 2023-02-28
 */
@Service
public class AppUserRelationServiceImpl extends ServiceImpl<AppUserRelationMapper, AppUserRelation> implements IAppUserRelationService {
    @Autowired
    private AppUserRelationMapper appUserRelationMapper;

    /**
     * 查询好友
     *
     * @param id 好友主键
     * @return 好友
     */
    @Override
    public AppUserRelation selectAppUserRelationById(Long id) {
        return appUserRelationMapper.selectAppUserRelationById(id);
    }

    /**
     * 查询好友列表
     *
     * @param appUserRelation 好友
     * @return 好友
     */
    @Override
    public List<AppUserRelation> selectAppUserRelationList(AppUserRelation appUserRelation) {
        return appUserRelationMapper.selectAppUserRelationList(appUserRelation);
    }

    /**
     * 新增好友
     *
     * @param appUserRelation 好友
     * @return 结果
     */
    @Override
    public int insertAppUserRelation(AppUserRelation appUserRelation) {
        return appUserRelationMapper.insertAppUserRelation(appUserRelation);
    }

    /**
     * 修改好友
     *
     * @param appUserRelation 好友
     * @return 结果
     */
    @Override
    public int updateAppUserRelation(AppUserRelation appUserRelation) {
        return appUserRelationMapper.updateAppUserRelation(appUserRelation);
    }

    /**
     * 批量删除好友
     *
     * @param ids 需要删除的好友主键
     * @return 结果
     */
    @Override
    public int deleteAppUserRelationByIds(Long[] ids) {
        return appUserRelationMapper.deleteAppUserRelationByIds(ids);
    }

    /**
     * 删除好友信息
     *
     * @param id 好友主键
     * @return 结果
     */
    @Override
    public int deleteAppUserRelationById(Long id) {
        return appUserRelationMapper.deleteAppUserRelationById(id);
    }

    @Override
    public List<Long> getFriendIds(Long userId) {
        return appUserRelationMapper.getFriendIds(userId);
    }

    @Override
    public List<Long> selectAppUserIds(AppUserRelation appUserRelation) {
        List<AppUserRelation> list = appUserRelationMapper.selectAppUserIds(appUserRelation);
        return list.stream().map(AppUserRelation::getFriendId).collect(Collectors.toList());
    }

    @Override
    public List<Long> getFriendIdToTimeLine(QueryWrapper<AppUserRelation> relationWrapper) {
        return this.appUserRelationMapper.getFriendIdToTimeLine(relationWrapper);
    }
}
